Repository navigation
Conversation
The bindings of SOFA components (bindings/Modules, bindings/SofaExporter) are
moved to bindings/Component, mirroring SOFA's Sofa/Component layout. Each SOFA
module Sofa.Component.<Area>.<Sub> gets a python module of the same name:
Sofa.SofaBaseTopology -> Sofa.Component.Topology.Container.Grid
Sofa.SofaDeformable -> Sofa.Component.SolidMechanics.Spring
Sofa.Component.SolidMechanics.FEM.Elastic
Sofa.SofaLinearSolver -> Sofa.Component.LinearSolver.Iterative
Sofa.SofaLinearSystem -> Sofa.Component.LinearSystem
Sofa.SofaConstraintSolver -> Sofa.Component.Constraint.Lagrangian.Solver
SofaExporter -> Sofa.Component.IO.Mesh
Sofa.FEM and Sofa.GL are not components: their bindings (previously
Sofa.SofaFEM and Sofa.SofaGL) move next to Sofa.Core in bindings/Sofa.
- A binding is only built when the SOFA module it binds is available.
- The old python modules are kept as deprecated aliases re-exporting the new
ones, and Bindings.Modules as a cmake alias of Bindings.Component. Outdated
compiled modules are removed from the build tree so they do not shadow them.
- SP3_add_python_module: compute the macOS rpath to site-packages from the
module depth, and set INSTALL_NAME_DIR on the module target.
- Stub generation: for SOFA modules having a compiled binding, the stubs of
the components without binding are merged in a .pyi next to the binding
instead of a package that would shadow it.
- Tests, examples and docs use the new module names. The matrix access test
scenes now load the plugins they use instead of relying on test order.
Most of the stubs generated by sofaStubgen.py for Sofa.Component did not parse (309 of 362), and many of the others failed when imported: - the constructor arguments without default value followed the optional 'template' argument, and the required and optional arguments were joined without a comma: the arguments are now keyword-only, separated by commas. - data fields named after a python keyword other than the few listed (eg. 'global'), duplicated or not valid identifiers were not filtered out, and the keyword ones were written as invalid class attributes: they are now written as comments. - descriptions ending with a quote closed the docstring early, and backslashes produced invalid escape sequences: they are now escaped. - array types were annotated 'TypeHints.SofaArray' while only 'SofaArray' is imported, raising a NameError when importing the stub. All the 369 generated stubs now compile and import.
restLength had no default while following arguments that have one, which
made the generated stub invalid python ("parameter without a default
follows parameter with a default"). Use 0, the default of the C++
constructor.
pybind11-stubgen can write imports such as 'import Sofa.Core' before 'from __future__ import annotations', which makes the .pyi files invalid python. After stub generation, move the __future__ imports right after the module docstring.
Contributor
|
Hi @fredroy Thanks for this work. Looks ok, just one open questions. Shouldn't we move the binding into a dedicated subdirectory of each Sofa.Component.XXX instead of centralizing all that into SofaPython3. If I remember correctly the choice of centralizing everything was a consequence SofaPython3 was a plugin that may be compiled after the compilation of each Sofa.Component's target. If we want SofaPython3 to be detected... it has to be injected at the beginning of the build process. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(no AI flag is present but obviously Claude did the heavy lifting here)
Lots of files are modified but mostly because of renaming and/or compat layer.
The refactoring aimed to replicate the same file structure as in the SOFA.Component directory. (Sofa.FEM and Sofa.GL as well)
It involved also some stubgen updates because of... stuff (did not really understand but it seems because of naming and bugs or whatever)
This is supposed not to break any existing scripts using SofaPytthon3.
For completeness, it would break in those cases:
Tested locally on macOS 27 (clang), ubuntu 26.04 (gcc and clang) and windows (MSVC26)
Claude summary:
And Claude summary for the stubgen: